package streamTest;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * IntersectionTest
 *
 * @author byc
 * @date 2021-12-08
 */
public class IntersectionTest {

    public static List<Long> listCheckIn(List<Long> listOld,List<Long> listNew){
        List<Long> intersectionList = new ArrayList<>();
        List<Long> intersection = listOld.stream().filter(item -> listNew.contains(item)).collect(Collectors.toList());
        for (Long aLong : intersection) {
            intersectionList.add(aLong);
        }
        return intersectionList;
    }

    public static List<Long> listCheckOut(List<Long> listOld,List<Long> listNew){
        List<Long> staggerList = new ArrayList<>();
        List<Long> reduce = listOld.stream().filter(item -> !listNew.contains(item)).collect(Collectors.toList());
        for (Long aLong : reduce) {
            staggerList.add(aLong);
        }
        return staggerList;
    }


    public static void main(String[] args) {
        List<Long> listOld = new ArrayList<>();
        listOld.add(1L);
        listOld.add(2L);
        listOld.add(3L);
        listOld.add(4L);
        listOld.add(5L);

        List<Long> listNew = new ArrayList<>();
        listNew.add(3L);
        listNew.add(4L);
        listNew.add(5L);
        listNew.add(6L);
        listNew.add(7L);

        List<Long> intersection1 = null;
        intersection1 = listCheckIn(listOld,listNew);
        List<Long> stagger1 = null;
        stagger1 = listCheckOut(listOld,intersection1);
        List<Long> stagger2 = null;
        stagger2 = listCheckOut(listNew,intersection1);

        System.out.println("交集：" + intersection1);
        System.out.println("old需删除" + stagger1);
        System.out.println("new需新增" + stagger2);

    }
}
